from numpy import zeros


class Element:
    def __init__(self):
        self.number_of_dof = 0
        self.stiffness_matrix = None
        self.element_nodes = []

    def print_debug_info(self):
        """
        This is a virtual method that should be defined
        in all subclasses of Element.
        """
        return None


class PiecewiseLinearElement:
    def __init__(self):
        self.element_id = element_id 
        self.element_node_ids = element_node_ids 

        
class FourNodeQuad(Element):

    def __init__(self, element_id, element_node_ids):
        self.element_id = element_id
        self.element_node_ids = element_node_ids
        self.centroid_coordinates = zeros(2)

    def print_debug_info(self):
        print "element id: " + str(self.element_id)
        print "global id of node 1: " + str(self.element_node_ids[0])
        print "global id of node 2: " + str(self.element_node_ids[1])
        print "global id of node 3: " + str(self.element_node_ids[2])
        print "global id of node 4: " + str(self.element_node_ids[3])
        print ""


class RodElement(Element):

    def __init__(self, element_id, youngs_modulus, area, \
                 length, element_nodes):
        self.element_id = element_id
        self.element_nodes = element_nodes
        self.youngs_modulus = youngs_modulus
        self.area = area
        self.length = length
        self.number_of_dof = 2
        self.set_stiffness()

    def print_debug_info(self):
        print "Element Type: Rod"
        print ""
        print "element id: " + str(self.element_id)
        print ""
        print "element node 1 id: " + str(self.element_nodes[0].node_id)
        print "element node 2 id: " + str(self.element_nodes[1].node_id)
        print ""
        print "element stiffness = " + str(self.stiffness_matrix)
        print ""

    def set_stiffness(self):
        stiffness = (self.youngs_modulus * self.area) / self.length
        self.stiffness_matrix = stiffness * ([-1.0, 1.0], [1.0, -1.0])
